package org.harlov.testsys.views.add_forms;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import org.harlov.testsys.db.diffs;
import org.harlov.testsys.db.tests;
import org.harlov.testsys.db.themes;
import org.harlov.testsys.views.creators_form;
import org.harlov.testsys.views.gui_factory;

public class add_test_form extends JFrame {
	
	private gui_factory gFactory;
	private JFrame mFrame;
	private String creator;
	private creators_form owner;
	
	public add_test_form (String _creator, creators_form _owner) {
		
		super ("Добавление нового теста");
		gFactory = new gui_factory(this);
		this.setPreferredSize(new Dimension(320,180));
		this.setSize(320,180);
		this.getContentPane().setLayout(null);
		this.setResizable(false);
		gui_factory.setCenterPosition(this);
		this.setVisible(true);
		mFrame = this;
		owner = _owner;
		creator = _creator;
		gFactory.newComboBox("cb_themes", themes.getThemes(), 150, 20,150,20);
		gFactory.newComboBox("cb_diffs", diffs.getDiffs(), 150, 40,150,20);
		gFactory.newText("t_name",150, 60,150,20);
		gFactory.newText("t_time", 150, 80,150,20);
		
		gFactory.newLabel("Тема теста","l_theme", 10, 20,100,20);
		gFactory.newLabel("Сложность","l_diff",10,40,100,20);
		gFactory.newLabel("Название теста", "l_name", 10, 60,130,20);
		gFactory.newLabel("Время", "l_time", 10, 80,130,20);
		
		gFactory.newButton("Добавить", "btn_add", 10, 100,130,20, new add_ok());
		gFactory.newButton("Отмена", "btn_cancel", 140, 100,130,20, new add_cancel());
		
	}
	
	
	class add_ok implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			tests.addTest(gFactory.getSelCombo("cb_themes")-1, gFactory.getSelCombo("cb_diffs"), creator,gFactory.getTextFrom("t_name"),
					Integer.parseInt(gFactory.getTextFrom("t_time")) );
			tests.getTestsView(creator);
			owner.compRepaint("tests_list");
			mFrame.dispose();
			
		}
				
	} 
	class add_cancel implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			mFrame.dispose();
			
		}
		
	}
	

}
